package com.example.domain;

import lombok.Data;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.util.StringUtils;

@Data
public class CarFactoryBean implements FactoryBean<Car> {
    // 注入
    private String carInfo;

    @Override
    public Car getObject() throws Exception {
        final Car car = new Car();
        final String[] infos = StringUtils.tokenizeToStringArray(carInfo, ",; ");
        car.setBrand(infos[0]);
        car.setMaxSpeed(Integer.parseInt(infos[1]));
        car.setPrice(Double.parseDouble(infos[2]));
        return car;
    }

    @Override
    public Class<?> getObjectType() {
        return Car.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }
}

